package com.mmo.cq.game.server.data;

import com.mmo.cq.game.server.bean.server.Server_Seed;
import com.mmo.cq.game.server.bean.user.UserInfo;
import com.mmo.cq.game.server.bean.user.UserSnap;
import lombok.Getter;
import lombok.Setter;
import org.wxd.cache.CachePack;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;

/**
 * 数据中心
 *
 * @author: Troy.Chen(無心道, 15388152619)
 * @version: 2023-02-02 20:20
 **/
@Getter
@Setter
@Resource
public class DataCenter {

    /** 全局的临时id，比如掉落物，怪物的唯一id */
    private final AtomicLong uidSeed = new AtomicLong();

    private final CachePack<Long, UserInfo> userCachePack = new CachePack<>();

    private final CachePack<Long, UserSnap> userSnapCachePack = new CachePack<>();

    /** id生成器 */
    private Server_Seed serverSeed;

    {

        userCachePack.setCacheSurvivalTime(TimeUnit.MINUTES.toMillis(20));
        userCachePack.setCacheHeartTimer(TimeUnit.MINUTES.toMillis(1));
        userCachePack.setCacheIntervalTime(TimeUnit.MINUTES.toMillis(1));

        userSnapCachePack.setCacheSurvivalTime(TimeUnit.MINUTES.toMillis(20));
        userSnapCachePack.setCacheHeartTimer(TimeUnit.MINUTES.toMillis(1));
        userSnapCachePack.setCacheIntervalTime(TimeUnit.MINUTES.toMillis(1));

    }

    /** 场景对象的临时uid, 比如掉落物，怪物的唯一id */
    public long newUid() {
        return uidSeed.incrementAndGet();
    }


}
